//
//  MBProgressHUD+progressHUD.m
//  HA
//
//  Created by sy on 2023/12/17.
//

#import "MBProgressHUD+progressHUD.h"

@implementation MBProgressHUD (progressHUD)


+ (MBProgressHUD *)showLoading:(UIView *)view {
    if (view == nil) view = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    return hud;
}

+ (void)showSuccess:(NSString *)success
{
    UIWindow *window =  [[[UIApplication sharedApplication] windows] objectAtIndex:0];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.square = YES;
    hud.label.text = success;
    hud.label.numberOfLines = 0;
    [hud hideAnimated:YES afterDelay:1.25];
}

+ (void)showError:(NSString *)error
{
    UIWindow *window =  [[[UIApplication sharedApplication] windows] objectAtIndex:0];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.square = YES;
    hud.label.text = error;
    hud.label.numberOfLines = 0;
    [hud hideAnimated:YES afterDelay:1.25];
}

+ (void)hideHUDForView:(UIView *)view
{
    if (view == nil) view = [[[UIApplication sharedApplication] windows] objectAtIndex:0];

    NSMutableArray *huds = [NSMutableArray array];
    NSArray *subviews = view.subviews;
    for (UIView *aView in subviews) {
        if ([aView isKindOfClass:[MBProgressHUD class]]) {
            [huds addObject:aView];
        }
    }
    for (MBProgressHUD *hud in huds) {
        hud.removeFromSuperViewOnHide = YES;
        [hud hideAnimated:YES];
    }
}


@end
